#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:jidi
@file:wework_app.py
@time:2022/08/21
"""
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

from app.wework.page.contact_page import ContactPage
from app.wework.page.search_page import SearchPage


class WeWorkApp:
    def __init__(self):
        caps = {
            "platformName": "Android",
            "appPackage": "com.tencent.wework",
            "appActivity": "com.tencent.wework.launch.LaunchSplashActivity",
            "noReset": "true",
            "unicodeKeyboard": True,
            'resetKeyboard': True
        }

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
        self.driver.implicitly_wait(5)

    def search(self):
        self.driver.find_element(AppiumBy.ID, 'kuo').click()
        return SearchPage(self.driver)

    def close(self):
        self.driver.quit()

    def contact(self):
        self.driver.find_element(AppiumBy.CSS_SELECTOR, '[text="通讯录"]').click()
        return ContactPage(self.driver)

